package com.hmdp.utils;

import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author amanda
 * @Description
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        // 判断是否需要拦截（ThreadLocal是否存在用户）
        if (UserHolder.getUser() == null) {
            response.setStatus(401);
            // 拦截
            return false;
        }
        // 放行
        return true;
    }

}
